require File.dirname(__FILE__) + '/../../../lib/tasks/compiler_tasks'
require 'test/unit'
require 'mocha'
require File.dirname(__FILE__) + '/../../../lib/facades'

class  WhenCallingCscTask < Test::Unit::TestCase

   
  def setup
    @frameworkDir = 'frameworkDir'
    @framework = mock()
    @framework.stubs(:framework_dir).returns(@frameworkDir)
    Rubicant::DotNet::Frameworks.expects(:get_framework).returns(@framework)
    @rsp_file = "@#{ENV['TEMP']}/csc.rsp"
    Rubicant::Runner.expects(:sh).with("frameworkDir\\csc.exe #{@rsp_file}")

    @mock_file = mock()
    File.stubs(:new).with("#{ENV['TEMP']}/csc.rsp", "w").returns(@mock_file)
    @mock_file.stubs(:close)
  end

  def test_should_call_csc_with_rsp_file_even_with_no_parameters

    Rubicant::Tasks::CscTask.new('csc')
    Rake.application['csc'].invoke
  end

  def test_should_call_csc_with_target_parameter
    target = 'library'

    @mock_file.expects(:puts).with(" /target:#{target}")
    Rubicant::Tasks::CscTask.new('csc2') do |csc|
      csc.target = target
    end

    Rake.application['csc2'].invoke
  end

  def test_should_call_csc_with_reference_parameter
    foo = 'foo.dll'
    bar = 'bar.dll'

    @mock_file.expects(:puts).with(" /reference:#{foo};#{bar}")

    Rubicant::Tasks::CscTask.new('csc3') do |csc|
      csc.references = [foo, bar]
    end

    Rake.application['csc3'].invoke
  end

  def test_should_call_csc_with_out_parameter
    out = "outfile.dll"

    @mock_file.expects(:puts).with(" /out:#{out}")
    Rubicant::Tasks::CscTask.new('csc4') do |csc|
      csc.out = out
    end

    Rake.application['csc4'].invoke
  end

  def test_should_call_csc_with_files
    foo = 'foo.cs'
    bar = 'bar.cs'
    @mock_file.expects(:puts).with(" #{foo} #{bar}")
    Rubicant::Tasks::CscTask.new('csc5') do |csc|
      csc.files = [foo, bar]
    end

    Rake.application['csc5'].invoke
  end

  def test_should_call_csc_with_debug

    @mock_file.expects(:puts).with(" /debug:full")
    Rubicant::Tasks::CscTask.new('csc6') do |csc|
      csc.debug = true
    end

    Rake.application['csc6'].invoke
  end

end

